import request from '@/utils/request';
import { stringify } from 'qs';
export async function allArticle(payload) {
  return request(`/admin/article/list`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`${stringify(payload)}`
  });
}

export async function saveAricle(payload) {
  console.log("saveAricle==>"+payload.article_detail);
  let reqPrams=`title=${payload.article_title}&summary=${payload.article_describe}&authorId=${payload.authorId}&coverPic=${payload.article_pic}`;
  payload.article_category.split("，").map(category=>{
    reqPrams+=`&category=${category}`
  })
  payload.article_tag.split("，").map(tag=>{
    reqPrams+=`&tag=${tag}`;
  })
  if(payload.article_createTime){
    reqPrams+=`&createTime=${payload.article_createTime}`;
  }
  if(payload.articleId){
    reqPrams+=`&articleId=${payload.articleId}`;
  }
  if(payload.article_detail){
    reqPrams+="&body="+encodeURIComponent(payload.article_detail);
  }
  return request(`/admin/article/add`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body: reqPrams
  });
}
export async function detailArticle(payload) {
  return request(`/admin/article/find/${payload}`);
}
export async function deleteArticle(payload) {
  return request(`/admin/article/delete/${payload.id}`);
}
export async function changeArticleState(payload) {
  return request(`/admin/article/state/${payload.id}`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`state=${payload.state}`
  });
}
export async function countArticle(payload) {
  return request(`/admin/article/count`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;'
    },
    body:`${stringify(payload)}`
  });
}
